﻿using System;
using System.Web;
using Archie.Retail.Data;
using Archie.Retail.Data.SqliteStorage;

namespace Archie.Retail.Site.Controllers
{
    public class DataManagerLocator
    {
        private static readonly Lazy<IDataManager> Instance = new Lazy<IDataManager>(() => new SqliteDataManager());

        public static IDataManager DataManager
        {
            get
            {
                GetDbName();
                return Instance.Value;
            }
        }

        // позволяет получить путь на сервере
        private static string GetDbName()
        {
            var path = System.Configuration.ConfigurationManager.AppSettings["dbPath"];
            string fullPath = HttpContext.Current.Server.MapPath(path);
            var replacedPath = fullPath.Replace("\\", "/");
            return replacedPath;
        }
    }
}
